<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title site-title">
		<legend>
			<a name="fixbar">请假申请</a>
		</legend>
	</fieldset>
	<form class="layui-form white-bg" id="manageask">
		<div class="layui-form-item">
			<label class="layui-form-label">起止时间</label>
			<div class="layui-input-block bannwit">

				<input type="text" class="layui-input" lay-verify="required"
					name="startDate" id="startTime" placeholder=" 请选择请假时间 ">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">请假类型</label>
			<div class="layui-input-block bannwit">
				<select name="type" id="type" lay-verify="required">
					<option value=""></option>
					<c:forEach items="${model }" var="c">
						<option value="${c.name }">${c.name }</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">请假事由</label>
			<div class="layui-input-block bannwit">
				<textarea name="reasonforleave" lay-verify="required"
					placeholder="请假事由" autocomplete="off" class="layui-input"
					style="height: 200px"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">上传请假条</label>
				<div class="layui-input-block">
					<div class="layui-upload-drag" id="photo">
						<i class="layui-icon">&#xe67c;</i>
						<p>点击上传，或将文件拖拽到此处</p>
					</div>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="hidden" name="leavefile" id="fileuuid" value="">
				<button class="layui-btn" lay-submit lay-filter="formaskform">确认请假</button>
			</div>
		</div>
	</form>
</body>
<script>
layui.use('form', function(){  //此段代码必不可少
    var form = layui.form;
    form.render();
});
layui.use('laydate', function(){
	var laydate = layui.laydate;
	laydate.render({
	    elem: '#startTime'
	    ,type: 'datetime'
	    ,range: true
	  });
});
</script>
<script>
layui.use('upload', function(){
    var upload = layui.upload;
    //执行实例
    var uploadInst = upload.render({
        elem: '#photo' //绑定元素
        ,url: 'toFilesave' //上传接口
        ,done: function(res){
            if(res.success){
            	$("#fileuuid").val(res.msg);
            	$("#photo").html('<img alt="" src="download?uuid='+res.msg+'" height="300px" title="点击重新选择">' );
            }else{
            	layer.open({
            		title: '上传失败'
            		,content: res.msg
            		,time: 2000
            	});   
            }
        }
        ,error: function(){
            
        }
    });
});
layui.use(['form'], function(){
	var form = layui.form;
	 //监听提交
	  form.on('submit(formaskform)', function(data){
		  console.info(data);
		  $.post("askForleave/goleave",data.field,function(res){
				if(res.success){
					layer.alert(res.msg, {icon: 1});
                    $("#manageask")[0].reset();
					$("#photo").html('<i class="layui-icon">&#xe67c;</i><p>点击上传，或将文件拖拽到此处</p>' );
				}else{
					layer.msg(res.msg, {icon: 1});
				}
			},'json');
	    return false;
	  });
	 
});
</script>
</html>